package com.yesjpt.web;

import com.alibaba.fastjson.JSONObject;
import com.yesjpt.domain.User;
import com.yesjpt.serv.UserServ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    //查询所有
    @Autowired
    private UserServ serv;

    @GetMapping("/findAll")
    public List<User> findAll() {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.findAll();
    }

    // 根据ID删除
    @GetMapping("/delete")
    public JSONObject deleteUser(String id) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.delete(id);
    }

    //更新用户昵称
    @GetMapping("/updateNickname")
    public JSONObject updateNickname(String id, String nickName) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.updateNickname(id, nickName);
    }

    // 新增用户
    @PostMapping("/add")
    public JSONObject add(@RequestBody User vo) {
        System.out.println(new Throwable().getStackTrace()[0]);
        return serv.add(vo);
    }
}
